package com.M10.BE.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.M10.BE.R;
import com.M10.BE.activity.AssetInfoActivity;
import com.fn.useries.model.Asset;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Lenovo
 * @desc
 * @time 2018/3/7 16:48
 */

public class AssetAdapter extends RecyclerView.Adapter<AssetAdapter.MasonryView> {
    private List<Asset> assets;
    private Context ctx;

    public AssetAdapter(ArrayList<Asset> list, Context context) {
        assets = list;
        ctx = context;
    }

    @Override
    public MasonryView onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_asset_list, parent, false);
        return new MasonryView(view);
    }

    @Override
    public void onBindViewHolder(MasonryView holder, final int position) {
        holder.name.setText(assets.get(position).getName());
        holder.no.setText(assets.get(position).getCode());
        holder.num.setText(assets.get(position).getCnum());
        holder.postion.setText(assets.get(position).getUseOrg());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ctx, AssetInfoActivity.class);
                intent.putExtra("asset", assets.get(position));
                ctx.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return assets.size();
    }

    public static class MasonryView extends RecyclerView.ViewHolder {
        TextView name;
        TextView no;
        TextView num;
        TextView postion;

        public MasonryView(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.tv_item_asset_name);
            no = (TextView) itemView.findViewById(R.id.tv_item_asset_no);
            num = (TextView) itemView.findViewById(R.id.tv_item_asset_num);
//            postion = (TextView) itemView.findViewById(R.id.tv_item_asset_postion);
        }

    }
}
